package com.danger.Activity;

import android.support.v7.app.AppCompatActivity;

import com.danger.Fragment.BackHandledFragment;
import com.danger.Fragment.BackHandledInterface;

/**
 * Created by 俊 on 2016/6/2.
 */
public abstract class BaseActivity extends AppCompatActivity implements BackHandledInterface {

    private BackHandledFragment selectedFragment;

    public abstract void initView();

    public abstract void initEvent();


    @Override
    public void onBackPressed() {
        if (selectedFragment == null || !selectedFragment.onBackPressed()) {
            if (getFragmentManager().getBackStackEntryCount() == 0) {
                super.onBackPressed();
            } else {
                getFragmentManager().popBackStack();
            }
        }
    }


    @Override
    public void setSelectedFragment(BackHandledFragment selectedFragment) {
        this.selectedFragment = selectedFragment;
    }
}
